package demo1;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ASUS
 * Date: 2024-03-09
 * Time: 10:25
 */
public class Test3 {
    public static void main(String[] args) {
        int[] pushA ={1,2,3,4,5};
        int[] popA = new int[0];
        if (isPopOrder(pushA,popA)){
            System.out.println(true);
        }

    }


    public static boolean isPopOrder(int[] pushA, int[] popA){
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for (int i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
            while (stack.peek() == popA[j]) {
                stack.pop();
                j++;
            }
        }
        return stack.empty();
    }
}
